package com.shangcheng.server.controller;

import com.shangcheng.model.domain.OmsOrderReturnApply;
import com.shangcheng.model.domain.OmsOrderReturnReason;
import com.shangcheng.model.vo.PageResult;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.OmsOrderReturnReasonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author JavaClimber
 * @version 1.0
 * @date 2022/5/15 0015 zihao
 */
@RestController
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {
    
    @Autowired
    private OmsOrderReturnReasonService omsOrderReturnReasonService;
    
    //添加退货原因
    @PostMapping("/create")
    public ResponseEntity create(@RequestBody OmsOrderReturnReason omsOrderReturnReason) {
        boolean b = omsOrderReturnReasonService.create(omsOrderReturnReason);
        if (b) {
            //如果返回ture代表添加成功
            return ResponseEntity.ok(new Result(200, "", "成功"));
        }
        return ResponseEntity.ok(new Result(403, "", "添加不成功"));
    }
    
    //批量删除退货原因
    @PostMapping("/delete")
    public ResponseEntity deletes(Long[] ids) {
        boolean b = omsOrderReturnReasonService.deletes(ids);
        if (b) {
            //如果返回ture代表添加成功
            return ResponseEntity.ok(new Result(200, "", "成功"));
        }
        return ResponseEntity.ok(new Result(403, "", "添加不成功"));
    }
    
    //分页查询退货原因
    @GetMapping("/list")
    public ResponseEntity lists(Integer pageNum, Integer pageSize) {
        PageResult pageResult = omsOrderReturnReasonService.lists(pageNum, pageSize);
        return ResponseEntity.ok(new Result(200, pageResult, "成功"));
    }
    
    //修改退货原因启用状态
    @PostMapping("/update/status")
    public ResponseEntity status(Long[] ids, Integer status) {
        boolean b = omsOrderReturnReasonService.status(ids, status);
        if (b) {
            //如果返回ture代表添加成功
            return ResponseEntity.ok(new Result(200, "", "成功"));
        }
        return ResponseEntity.ok(new Result(403, "", "修改不成功"));
    }
    
    //修改退货原因
    @PostMapping("/update/{id}")
    public ResponseEntity updateById(@PathVariable String id, @RequestBody OmsOrderReturnReason omsOrderReturnReason) {
        boolean b = omsOrderReturnReasonService.updateByIdss(id, omsOrderReturnReason);
        if (b) {
            //如果返回ture代表添加成功
            return ResponseEntity.ok(new Result(200, "", "成功"));
        }
        return ResponseEntity.ok(new Result(403, "", "修改不成功"));
    }
    
    //获取单个退货原因详情信息
    @GetMapping("{id}")
    public ResponseEntity getById(@PathVariable Long id) {
       OmsOrderReturnReason omsOrderReturnReason = omsOrderReturnReasonService.getByIdd(id);
        return ResponseEntity.ok(new Result(200, omsOrderReturnReason, "成功"));
    }
    
}
